package com.jack.leetcode.eachproblem_2020;

/**
 * Created by zhang_j on 2020/11/3
 */
public class 有效的山脉数组 {

    public static void main(String[] args) {
        int[] a = {3,5,5};
        System.out.println(validMountainArray(a));
        int[] b = {2, 1};
        System.out.println(validMountainArray(b));
        int[] c = {0,3,2,1};
        System.out.println(validMountainArray(c));
        int[] d = {0,1,2,3,4,5,6,7,8,9};
        System.out.println(validMountainArray(d));
    }

    public static boolean validMountainArray(int[] A) {
        if(A == null || A.length < 3){
            return false;
        }
        int n = A.length;
        int corner = 0;
        if(A[1] < A[0]){
            return false;
        }
        for(int i = 0;i < n - 1;i++){
            if(A[i + 1] == A[i]){
                return false;
            }
            if(corner == 0 && A[i + 1] > A[i]){
                continue;
            }
            if(corner == 1 && A[i + 1] < A[i]){
                continue;
            }
            if(A[i + 1] < A[i]){
                corner++;
                continue;
            }
            return false;
        }
        return corner == 1;
    }
}
